package com.terren.statistic.common.util;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class ExcelUtil {
	
	public static String excelSuffix = ".xlsx";

	/**
	 * 结果写入excel文件
	 * 
	 * @param excelBook
	 */
	public File writeFile(XSSFWorkbook excelBook, String name, String path) throws Exception {
		FileOperateUtils.mkdirs(path);
		File excelFile = null;
		FileOutputStream out = null;
		try {
			//String excelName = CommonUtil.getSingleId();
			String excelPath = path + name + excelSuffix;
			excelFile = new File(excelPath);
			if (excelFile.exists()) {
				excelFile.delete();
			}
			out = new FileOutputStream(excelFile);
			excelBook.write(out);
			out.close();
		} finally {
			if (out != null) {
				try {
					out.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		return excelFile;
	}
}
